/**
 * 
 */
package org.nus;

import java.io.OutputStream;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

/**
 * Action Class to show Data between dates
 * @author Xiaohui
 * 
 */
public class ShowDataBetweenDatesAction extends Action {
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {

		try {
			// get imei
			HttpSession session = request.getSession();
			String imei = (String) session.getAttribute("this_imei");
			if (imei == null || imei.length() == 0) {
				System.err.println("In export action, imei:" + imei);
			}
			// Get parameters
			String year1 = request.getParameter("start_gpsyear");
			String mon1 = request.getParameter("start_gpsmonth");
			String day1 = request.getParameter("start_gpsday");
			String hh1 = request.getParameter("start_gpshh");
			String mm1 = request.getParameter("start_gpsmm");
			String ss1 = request.getParameter("start_gpsss");

			String starttime = year1 + "-" + mon1 + "-" + day1 + " " + hh1
					+ ":" + mm1 + ":" + ss1;

			String year2 = request.getParameter("end_gpsyear");
			String mon2 = request.getParameter("end_gpsmonth");
			String day2 = request.getParameter("end_gpsday");
			String hh2 = request.getParameter("end_gpshh");
			String mm2 = request.getParameter("end_gpsmm");
			String ss2 = request.getParameter("end_gpsss");

			String endtime = year2 + "-" + mon2 + "-" + day2 + " " + hh2 + ":"
					+ mm2 + ":" + ss2;

			DBDisplayer displayer = new DBDisplayer(imei);
			session.setAttribute("data_between_time", displayer
					.getDisplayDataBetweenTime(starttime, endtime));
			// put the export data in session
			session.setAttribute("exportData", displayer
					.getExportDataBetweenTime(starttime, endtime));
			// put show track data in session
			session.setAttribute("trackData", displayer.getLatLonBetweenTimes(
					starttime, endtime));

		} catch (Exception e) {
			e.printStackTrace();
		}
		return mapping.findForward("success");

	}
}
